package com.niit.controller;

import com.niit.bean.R;
import com.niit.entity.User;
import com.niit.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = {"用户接口"})
@CrossOrigin
@RestController
@RequestMapping("/rec/user")
public class UserController {

    @Autowired
    private UserService userService;//将service层的接口注入到这里来

    @ApiOperation(value = "登录")
    @PostMapping("login")
    public R getUserById(@RequestBody User user){
        return userService.getUser(user);
    }

    @ApiOperation(value = "注册")
    @PostMapping("register")
    public R register(@RequestBody User user){
        return userService.addNewUser(user);
    }

    @ApiOperation(value = "获取所有用户列表")
    @GetMapping("getUserList")
    public R getUserList(){
        return userService.getUserList();
    }

    @ApiOperation(value = "更新用户")
    @PutMapping("updateUser")
    public R updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @ApiOperation(value = "通过username删除用户")
    @DeleteMapping("deleteUser/{username}")
    public R deleteUser(@PathVariable String username){
        return userService.deleteUser(username);
    }
}
